package cn.edu.scau.cmi.chenjiale.comprehension.service;

import java.util.List;

import cn.edu.scau.cmi.chenjiale.comprehension.dao.StudentDAO;
import cn.edu.scau.cmi.chenjiale.comprehension.entity.Student;

/**
 * 学生操作业务类
 * 
 * @author chen.jiale
 * @date 2019/05/07
 *
 */
public class StudentService {
	private StudentDAO studentDAO = new StudentDAO();

	/**
	 * 添加学生
	 * 
	 * @param student
	 * @return
	 */
	public boolean add(Student student) {
		studentDAO.save(student);
		return true;
	}

	/**
	 * 删除学生
	 * 
	 * @param student
	 * @return
	 */
	public boolean delete(Student student) {
		studentDAO.delete(student);
		return true;
	}

	/**
	 * 修改学生
	 * 
	 * @param student
	 * @return
	 */
	public boolean update(Student student) {
		studentDAO.attachDirty(student);
		return true;
	}

	/**
	 * 根据学号查询
	 * 
	 * @param id
	 * @return
	 */
	public Student findById(Long id) {
		Student student = studentDAO.findById(id);
		return student;
	}

	/**
	 * 根据姓名查询
	 * 
	 * @param name
	 * @return
	 */
	public List findByName(String name) {
		List students = studentDAO.findByName(name);
		return students;
	}

	/**
	 * 查询所有学生
	 * 
	 * @return
	 */
	public List findAll() {
		List students = studentDAO.findAll();
		return students;
	}

	public static void main(String[] args) {
		StudentService service = new StudentService();
		Student student = new Student();
		student.setId(104);
		student.setName("陈佳乐");
		service.add(student);
	}
}
